# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of libnvme.
# Copyright (c) 2021 Dell Inc.
#
# Authors: Martin Belanger <Martin.Belanger@dell.com>
#
sources = [
    'nvme/base64.c',
    'nvme/crc32.c',
    'nvme/fabrics.c',
    'nvme/filters.c',
    'nvme/ioctl.c',
    'nvme/linux.c',
    'nvme/log.c',
    'nvme/mi-mctp.c',
    'nvme/mi.c',
    'nvme/nbft.c',
    'nvme/sysfs.c',
    'nvme/tree.c',
    'nvme/util.c',
]

if json_c_dep.found()
    sources += 'nvme/json.c'
else
    sources += 'nvme/no-json.c'
endif

deps = [
    json_c_dep,
    keyutils_dep,
    libdbus_dep,
    liburing_dep,
    openssl_dep,
]

source_dir = meson.current_source_dir()
mapfile = 'libnvme.map'
version_script_arg = join_paths(source_dir, mapfile)

libnvme = library(
    'nvme', # produces libnvme.so
    sources,
    version: library_version,
    link_args: ['-Wl,--version-script=' + version_script_arg],
    dependencies: deps,
    link_depends: mapfile,
    c_args: config_h_arg,
    include_directories: [incdir, internal_incdir],
    install: true,
    link_with: libccan,
)

pkg = import('pkgconfig')
pkg.generate(libnvme,
    filebase: meson.project_name(),
    name: meson.project_name(),
    version: meson.project_version(),
    description: 'Manage "libnvme" subsystem devices (Non-volatile Memory Express)',
    url: 'http://github.com/linux-nvme/libnvme/',
)

libnvme_dep = declare_dependency(
    include_directories: ['.'],
    dependencies: [
      json_c_dep.partial_dependency(compile_args: true, includes: true),
    ],
    link_with: libnvme,
)

# test library with all symbols visible, to use for MI unit tests. Should
# match libnvme above, but with no version script, and install: false.
libnvme_test = library(
    'nvme-test', # produces libnvme-test.so
    sources,
    dependencies: deps,
    c_args: config_h_arg,
    include_directories: [incdir, internal_incdir],
    install: false,
    link_with: libccan,
)

libnvme_test_dep = declare_dependency(
    include_directories: ['.'],
    link_with: libnvme_test,
)

mode = ['rw-r--r--', 0, 0]
install_headers([
       'libnvme.h',
       'libnvme-mi.h',
    ],
    install_mode: mode,
)
install_headers([
        'nvme/fabrics.h',
        'nvme/filters.h',
        'nvme/ioctl.h',
        'nvme/linux.h',
        'nvme/log.h',
        'nvme/nbft.h',
        'nvme/tree.h',
        'nvme/types.h',
        'nvme/util.h',
        'nvme/mi.h',
    ],
    subdir: 'nvme',
    install_mode: mode,
)
